package drawtest;


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DrawPoints
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{

//			    final Display d = new Display();
//			    final Shell shell = new Shell(d);
//
//			    shell.setSize(500, 500);
//
//			    shell.setLayout(new FillLayout());
//
//			    // Create a canvas
//			    Canvas canvas = new Canvas(shell, SWT.NONE);
//
//			    canvas.addPaintListener(new PaintListener() {
//			      public void paintControl(PaintEvent e) {
//			        Canvas canvas = (Canvas) e.widget;
//			        int maxX = canvas.getSize().x-10;
//			        int maxY = canvas.getSize().y-10;
//
//			        int halfY = (int) maxY / 2;
//
//			        e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_BLACK));
//			        e.gc.drawLine(0, halfY, maxX, halfY);
//			        
//			        for (int i = 0; i < maxX; i++) {
//				        e.gc.setForeground(e.display.getSystemColor(SWT.COLOR_RED));
//				        //e.gc.setBackground(e.display.getSystemColor(SWT.COLOR_RED));
//				        for(int k=0;k<5;k++){
//
//					          e.gc.drawOval(i-k/2, getNormalizedSine(i, halfY, maxX)-k/2,k,k);
//				        }
//			        }
//			      }
//			      int getNormalizedSine(int x, int halfY, int maxX) {
//			        double piDouble = 2 * Math.PI;
//			        double factor = piDouble / maxX;
//			        return (int) (Math.sin(x * factor) * halfY + halfY);
//			      }      
//			    });    
//			    
//			    
//			    shell.open();
//			    while (!shell.isDisposed()) {
//			      if (!d.readAndDispatch())
//			        d.sleep();
//			    }
//			    d.dispose();
//			  }

		
		
		Display display = new Display();
		 Shell shell = new Shell(display); 
		 

		
		    shell.setText("Drawing Example");


		    /**/
		    final Canvas canvas = new Canvas(shell, SWT.NONE);
		    canvas.setSize(150, 150);
		    canvas.setLocation(20, 20);
		    shell.setSize(500, 420);
		    
		    Button b = new Button(shell,0);
		    b.setText("TEST");
			b.setLayoutData(new RowLayout());
			b.addSelectionListener(new SelectionListener()
			{
				
				@Override
				public void widgetSelected(SelectionEvent arg0)
				{
					System.out.println("widgetSelected");
					;

				}
				
				@Override
				public void widgetDefaultSelected(SelectionEvent arg0)
				{
				}

				
			});

			canvas.addPaintListener( new PaintListener()
			{
				
				@Override
				public void paintControl(PaintEvent arg0)
				{
//					arg0.gc.drawRectangle(10, 10, 40, 45);
//					arg0.gc.drawRectangle(0, 0,149, 149);
//					arg0.gc.drawOval(65, 10, 30, 35);
//					arg0.gc.drawLine(130, 10, 90, 80);
//					arg0.gc.drawPolygon(new int[] { 20, 70, 45, 90, 70, 70 });
//					arg0.gc.drawPolyline(new int[] { 10, 120, 70, 100, 100, 130, 130, 75 });
					int xx = (int) (10+Math.random()*140);
					int yy = (int) (10+Math.random()*140);;
					arg0.gc.drawOval(xx, yy, 20, 20); 
					arg0.gc.dispose();
					
				}
			});
		    

		    shell.open();
		    /**/

//		    shell.pack();
//		    shell.open();
//		    shell.setSize(300, 320);
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			display.dispose();

	}


}
